<?php
/**
 * (logic)
 */
namespace App\Logic\MonthlyReportLT;

use App\Models\MonthlyReportLT\Payment\PaymentSales;
use App\Models\MonthlyReportLT\Payment\PaymentThFee;
class CheckPaymentTh
{
    public static function exe($date)
    {
        if('null' == $date){
            $time = strtotime('midnight first day of -1 month');
        }else{
            $time = strtotime($date);
        }
        try{
            $date = date('Y-m-01',$time);
            PaymentThFee::query()
                ->where('report_date',$date)
                ->orderBy('id')
                ->chunk(50, function ($lines){
                    foreach($lines as $line){
                        $count = PaymentSales::query()
                            ->where('report_date',$line->report_date)
                            ->where('psku_id',$line->psku_id)
                            ->count();
                        if($count == 0){
                            $line->status = 2;
                            $line->save();
                            echo 'psku_id:'.$line->psku_id.PHP_EOL;
                        }
                    }
                });
        }catch (\Exception $e){
            report($e);
        }
    }
}
